I have some code for a DXL Attribute that is supposed to loop through all out-links and, if it contains a particular attribute type, display the values that are selected for that attribute. For example, if you have an attribute called favoriteFood with the values: Fruits, Pizza, Pasta, Meat and Potatoes, and Stew. However, in some cases (not all), the value "Fruits" is being displayed even though it is not selected in any of the linked-to objects. Here is the main portion of the code that runs once we've made sure that the appropriate link module exists:
void showOut(Object o, int depth) {
Link l
LinkRef lr
ModName_ otherMod = null
ModuleVersion otherVersion = null
Object othero
Skip Baselines = createString
Item linkModItem = itemFromID("488795bfc9-000a7b");
if (null linkModItem) {
display("<<Link module not found>>")
} else if (type(linkModItem) != "Link") {
display("<<Invalid link module index")
} else {
string linkModName = fullName(linkModItem)
for l in all(o->linkModName) do {
otherVersion = targetVersion l
otherMod = module(otherVersion)
if (null otherMod || isDeleted otherMod) continue
othero = target l //Get the object being linked to
if (null othero) continue
if (isDeleted othero) continue
if (depth==1) {
int attr_int = 0
AttrType at = find(current Module, "*Baseline Applicable")
for (attr_int=0; attr_int < at.size; attr_int++) {
s = at.strings[attr_int];
if (s != "")
put(Baselines, s, s)
}
}
}
}
//Display values collected in Baselines skip list
string s2 = null;
string s3 = null;
for (s2 in Baselines do {
s3 = (string key Baselines)
display(s3)
}
delete(Baselines)
}
My assumption is that only the items selected from the enum are saved in at, but somehow, the first item in the list is, at times, being displayed even when none of the linked objects have the value selected.
I hope this makes some sense. If you need any other info, please let me know.
Chris chrscote - Thu Sep 20 15:33:08 EDT 2018 |
Re: Displaying selected items from multi-select enumeration so, what you basically do, if I understood the code correctly, is: for every applicable out link look at the definition of the attribute "Baseline Applicable" in the target module. Display every baseline that is allowed in the target module.
I assume that you rather wanted sth like "Display every baseline that is checked in the target object". That could be achieved by changing line 30 if (isMember(othero."Baseline Applicable", s)) put (Baselines, s, s) Edit: with that being said, if this is really your goal, you could make life way easier for you, by just replacing lines 7, 25-31 and 35-42 by l24:if (depth==1) display othero."Baseline Applicable" "" 2nd Edit: attention: I now see that you look at the definition of "Baseline Applicable" in the "current Module". That is wrong almost every time. "current Module" can change quite fast. If you ever need a module, e.g. for retrieving attribute definitions, use functions like "module obj" (i.e. the module where the currently to be displayed object resides in) or "module othero" (i.e. the module where the target object resides in" |
Re: Displaying selected items from multi-select enumeration Mike.Scharnow - Fri Sep 21 01:39:44 EDT 2018 so, what you basically do, if I understood the code correctly, is: for every applicable out link look at the definition of the attribute "Baseline Applicable" in the target module. Display every baseline that is allowed in the target module.
I assume that you rather wanted sth like "Display every baseline that is checked in the target object". That could be achieved by changing line 30 if (isMember(othero."Baseline Applicable", s)) put (Baselines, s, s) Edit: with that being said, if this is really your goal, you could make life way easier for you, by just replacing lines 7, 25-31 and 35-42 by l24:if (depth==1) display othero."Baseline Applicable" "" 2nd Edit: attention: I now see that you look at the definition of "Baseline Applicable" in the "current Module". That is wrong almost every time. "current Module" can change quite fast. If you ever need a module, e.g. for retrieving attribute definitions, use functions like "module obj" (i.e. the module where the currently to be displayed object resides in) or "module othero" (i.e. the module where the target object resides in" Thanks Mike. Adding the isMember check seems to have helped to make sure that only those items that are selected in both objects are displayed. |